//turret.txt - Simple script for turrets
//Cell 0,1 - Stuff done flag. If both 0, nothing. Otherwise If non-zero, this 
//turret wont attack. If the turret is itself attacked, will set the not-attack setting back to 0.
//Cell 2,3 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.

begincreaturescript;

short i,target;
short shield_mes = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Charged Drakon");
	change_max_health(ME,400);
	set_walk_speed(ME,0);
	set_boss_level(ME,2);
	set_new_abil(ME,20);
	bless_char(ME,2);
	
	set_resistance(ME,0,99);
	set_resistance(ME,1,99);
	set_resistance(ME,2,99);
	set_resistance(ME,6,99);
	break;

beginstate DEAD_STATE;
	if ((get_memory_cell(2) != 0) || (get_memory_cell(3) != 0))
		inc_flag(get_memory_cell(2),get_memory_cell(3),1);
break;

beginstate START_STATE; 
	if ((gf(80,9) == 0) && (gf(80,10) > 0))
		end();
		
	if (gf(80,5) > 0) {
		set_resistance(ME,0,50);
		set_resistance(ME,1,25);
		set_resistance(ME,6,25);
		}
	if (who_shot_me() >= 0) {


		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}

	if ((gf(80,6) > 0) && (char_ok(34) == FALSE)) {
		if (summon_creature(26)) {
			set_summon_level(34,1);
			place_particle_num(34,10,7,10);
			
			run_char_animation(2,1,50);	
			pc_heard_sound_delay(136,100);						
			}
		}
	if ((gf(80,6) > 0) && (char_ok(35) == FALSE)) {
		if (summon_creature(27)) {
			set_summon_level(35,1);
			place_particle_num(35,10,7,10);
			set_level(35,35);
			set_attack_bonus(35,12);
			set_new_abil(35,15);
			
			run_char_animation(2,1,50);	
			pc_heard_sound_delay(136,100);						
			}
		}
				
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (gf(80,5) > 0) {
		set_resistance(ME,0,50);
		set_resistance(ME,1,25);
		set_resistance(ME,6,25);
		}

	if (target_ok() == FALSE)
		set_state(START_STATE);
		
	if ((get_health(ME) < get_max_health(ME) - 40) && (shield_mes == 0) && (gf(80,5) == 0)) {
		shield_mes = 1;
		print_str_color("The power flowing through the conduits seems to be shielding the drakon.",3);
		}
		
	if (dist_to_char(get_target()) > 8) {
		set_foe_target(ME,-1);
		turret_heal();
		set_state(START_STATE);
		}

	if ((gf(80,6) > 0) && (char_ok(34) == FALSE)) {
		if (summon_creature(26)) {
			set_summon_level(34,1);
			place_particle_num(34,10,7,10);
			
			print_named_str(ME,"makes a new creation!");
			run_char_animation(2,1,50);	
			pc_heard_sound_delay(136,100);						
			end();
			}
		}
	if ((gf(80,6) > 0) && (char_ok(35) == FALSE)) {
		if (summon_creature(27)) {
			set_summon_level(35,1);
			place_particle_num(35,10,7,10);
			set_level(35,32);
			set_attack_bonus(35,10);
			set_new_abil(35,15);
			
			print_named_str(ME,"makes a new creation!");
			run_char_animation(2,1,50);	
			pc_heard_sound_delay(136,100);						
			end();
			}
		}
	
	if ((get_health(ME) < get_max_health(ME) - 60) && (get_ran(1,0,12) == 10))
		shield_mes = 0;

	do_attack();

	turret_heal();
break;

beginstate TALKING_STATE;
	print_str("All it really is is a big fungus. It can't communicate at all.");
break;